| Conditions | 1 |
| Paths | 4 |
| Total Lines | 87 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 7 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | var spauth = require('node-sp-auth'); |
||
| 10 | .then(function (data) { |
||
| 11 | var internalQueryStructureGeneric = MyCustomFunctions.internalQueryStructureArray(0); |
||
| 12 | request.get(MyCustomFunctions.buildRequestQuery(targetSharePoint.URL, internalQueryStructureGeneric, '', 'Lists', data)).then(function (response) { |
||
| 13 | var dataObjectLists = response.d.results; |
||
| 14 | if (Object.keys(dataObjectLists).length > 0) { |
||
| 15 | var wStreamListViews = fs.createWriteStream(config.General.PathForExtracts + config.General.MetaDataFileName.Views + '.csv', {encoding: 'utf8'}); // initiate MetaData for Views |
||
| 16 | wStreamListViews.write('"List Name"' + config.General.ListSeparator + '"' + Object.keys(config.SharePoint.MetaDataOutput.Views).join('"' + config.General.ListSeparator + '"') + '"\n'); // Headers for Views |
||
| 17 | var dataListLight = []; |
||
| 18 | var counter = 0; |
||
| 19 | dataObjectLists.forEach(function (item) { |
||
| 20 | dataListLight[counter] = MyCustomFunctions.buildCurrentListAttributeValues(config.SharePoint.MetaDataOutput.Lists, item); |
||
| 21 | counter++; |
||
| 22 | }); |
||
| 23 | var wStreamList = fs.createWriteStream(config.General.PathForExtracts + config.General.MetaDataFileName.Lists + '.csv', {encoding: 'utf8'}); // initiate MetaData for Lists |
||
| 24 | wStreamList.write('"' + Object.keys(dataListLight[0]).join('"' + config.General.ListSeparator + '"') + '"\n'); // headers of MetaData for Lists |
||
| 25 | var wStreamListFields = fs.createWriteStream(config.General.PathForExtracts + config.General.MetaDataFileName.Fields + '.csv', {encoding: 'utf8'}); // initiate MetaData for Fields |
||
| 26 | wStreamListFields.write('"List"' + config.General.ListSeparator + '"' + Object.keys(config.SharePoint.MetaDataOutput.Fields).join('"' + config.General.ListSeparator + '"') + '"\n'); // headers of MetaData for Fields |
||
| 27 | dataListLight.forEach(function (crtListParameters) { // parse each List |
||
| 28 | if (MyCustomFunctions.decideBlackListWhiteList(crtListParameters.Hidden, false, config.SharePoint.Filters.Lists.NotHidden.BlackList, true, config.SharePoint.Filters.Lists.Hidden.WhiteList, crtListParameters.Title)) { // check current List against configured BlackList and WhiteList besides considering user defined Lists |
||
| 29 | wStreamList.write('"' + Object.keys(crtListParameters).map(function (x) { // records detail of current List |
||
| 30 | return crtListParameters[x]; |
||
| 31 | }).join('"' + config.General.ListSeparator + '"') + '"\n'); |
||
| 32 | request.get(MyCustomFunctions.buildRequestQuery(targetSharePoint.URL, internalQueryStructureGeneric, crtListParameters.Title, 'Fields', data)).then(function (response) { // Dynamically detect structure of the list, extracting the Field names and their text to display |
||
| 33 | var dataObject = response.d.results; |
||
| 34 | if (Object.keys(dataObject).length > 0) { |
||
| 35 | var fieldAttributes = []; |
||
| 36 | var counter = 0; |
||
| 37 | dataObject.forEach(function (item) { |
||
| 38 | var crtRecordFieldWillBeExtracted = MyCustomFunctions.decideBlackListWhiteList(item.CanBeDeleted, true, config.SharePoint.Filters.Fields.CanBeDeleted.BlackList, false, config.SharePoint.Filters.Fields.CannotBeDeleted.WhiteList, item.InternalName); // check current Field against configured BlackList and WhiteList besides considering user defined Fields |
||
| 39 | if (config.SharePoint.Filters.Lists.Hidden.WhiteList.indexOf(crtListParameters.Title) > -1) { // for certain Lists all existing fields should be retrieved |
||
| 40 | crtRecordFieldWillBeExtracted = true; |
||
| 41 | } |
||
| 42 | if (crtRecordFieldWillBeExtracted) { |
||
| 43 | fieldAttributes[item.Title] = {'Technical Name': item.StaticName, 'Type': item.TypeAsString}; |
||
| 44 | counter++; |
||
| 45 | wStreamListFields.write('"' + crtListParameters.Title + '"' + config.General.ListSeparator + '"' + MyCustomFunctions.buildCurrentRecordValues(config.SharePoint.MetaDataOutput.Fields, item).join('"' + config.General.ListSeparator + '"') + '"\n'); // fields of current List |
||
| 46 | } |
||
| 47 | }); |
||
| 48 | var internalQueryStructureItem = MyCustomFunctions.internalQueryStructureArray(crtListParameters.Records); |
||
| 49 | request.get(MyCustomFunctions.buildRequestQuery(targetSharePoint.URL, internalQueryStructureItem, crtListParameters.Title, 'Items', data)).then(function (response) { // Get the actual values from current list |
||
| 50 | var wstream = fs.createWriteStream(config.General.PathForExtracts + crtListParameters.Title + '.csv', {encoding: 'utf8'}); |
||
| 51 | wstream.write('"' + Object.keys(fieldAttributes).join('"' + config.General.ListSeparator + '"') + (crtListParameters['Versioning Enabled'] ? '"' + config.General.ListSeparator + '"Version' : '') + '"\n'); // writing headers for records within current list |
||
| 52 | var dataObjectValues = response.d.results; |
||
| 53 | if (Object.keys(dataObjectValues).length > 0) { |
||
| 54 | dataObjectValues.forEach(function (item) { |
||
| 55 | wstream.write('"' + MyCustomFunctions.buildCurrentItemValues(fieldAttributes, item).join('"' + config.General.ListSeparator + '"') + (crtListParameters['Versioning Enabled'] ? '"' + config.General.ListSeparator + '"' + item.OData__UIVersionString : '') + '"\n'); // writing current record values |
||
| 56 | }); |
||
| 57 | } |
||
| 58 | wstream.end(); |
||
| 59 | }); |
||
| 60 | } |
||
| 61 | }); |
||
| 62 | request.get(MyCustomFunctions.buildRequestQuery(targetSharePoint.URL, internalQueryStructureGeneric, crtListParameters.Title, 'Views', data)).then(function (responseViews) { |
||
| 63 | var dataViewObject = responseViews.d.results; |
||
| 64 | if (Object.keys(dataViewObject).length > 0) { |
||
| 65 | dataViewObject.forEach(function (crtView) { |
||
| 66 | wStreamListViews.write('"' + crtListParameters.Title + '"' + config.General.ListSeparator + '"' + MyCustomFunctions.buildCurrentRecordValues(config.SharePoint.MetaDataOutput.Views, crtView).join('"' + config.General.ListSeparator + '"') + '"\n'); // writing current record values |
||
| 67 | }); |
||
| 68 | } |
||
| 69 | }); |
||
| 70 | } |
||
| 71 | }); |
||
| 72 | wStreamList.end(); |
||
| 73 | } |
||
| 74 | }); |
||
| 75 | request.get(MyCustomFunctions.buildRequestQuery(targetSharePoint.URL, internalQueryStructureGeneric, '', 'SiteGroups', data)).then(function (response) { |
||
| 76 | var dataObjectValues = response.d.results; |
||
| 77 | if (Object.keys(dataObjectValues).length > 0) { |
||
| 78 | var wStreamGroups = fs.createWriteStream(config.General.PathForExtracts + config.General.MetaDataFileName.SiteGroups + '.csv', {encoding: 'utf8'}); // initiate MetaData for Groups |
||
| 79 | wStreamGroups.write('"' + Object.keys(config.SharePoint.MetaDataOutput.SiteGroups).join('"' + config.General.ListSeparator + '"') + '"\n'); // Headers for Groups |
||
| 80 | var wStreamGroupMembers = fs.createWriteStream(config.General.PathForExtracts + config.General.MetaDataFileName.SiteGroupMembers + '.csv', {encoding: 'utf8'}); // initiate MetaData for Group Members |
||
| 81 | wStreamGroupMembers.write('"Group"' + config.General.ListSeparator + '"' + Object.keys(config.SharePoint.MetaDataOutput.SiteGroupMembers).join('"' + config.General.ListSeparator + '"') + '"\n'); // Headers for Group Members |
||
| 82 | dataObjectValues.forEach(function (crtItemGroup) { |
||
| 83 | wStreamGroups.write('"' + MyCustomFunctions.buildCurrentRecordValues(config.SharePoint.MetaDataOutput.SiteGroups, crtItemGroup).join('"' + config.General.ListSeparator + '"') + '"\n'); // writing current record values |
||
| 84 | request.get(MyCustomFunctions.buildRequestQuery(targetSharePoint.URL, internalQueryStructureGeneric, crtItemGroup.Id, 'GroupMembers', data)).then(function (responseMembers) { |
||
| 85 | var dataObjectMemberValues = responseMembers.d.results; |
||
| 86 | if (Object.keys(dataObjectMemberValues).length > 0) { |
||
| 87 | dataObjectMemberValues.forEach(function (crtItemGroupMember) { |
||
| 88 | wStreamGroupMembers.write('"' + crtItemGroup.Title + '"' + config.General.ListSeparator + '"' + MyCustomFunctions.buildCurrentRecordValues(config.SharePoint.MetaDataOutput.SiteGroupMembers, crtItemGroupMember).join('"' + config.General.ListSeparator + '"') + '"\n'); // writing current record values |
||
| 89 | }); |
||
| 90 | } |
||
| 91 | }); |
||
| 92 | }); |
||
| 93 | wStreamGroups.end(); |
||
| 94 | } |
||
| 95 | }); |
||
| 96 | }); |
||
| 97 |